//
//  MainViewController.swift
//  iTrackpad
//
//  Created by lbxia on 2021/9/16.
//

import UIKit

class MainViewController: UIViewController {

    var newWindow : UIWindow?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.edgesForExtendedLayout = []

        self.view.backgroundColor = UIColor.gray
       
    }
    
     func hiddenWindow(){
        
        self.newWindow?.isHidden = true
//        self.newWindow?.resignKey()
        self.newWindow = nil
    }

    @IBAction func top(_ sender: Any) {
        
        let trackview = TrackpadView()
        trackview.backgroundColor = .lightGray
        self.view.addSubview(trackview)
        trackview.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            trackview.leftAnchor.constraint(equalTo: self.view.leftAnchor),
            trackview.topAnchor.constraint(equalTo: self.view.topAnchor),
            trackview.rightAnchor.constraint(equalTo: self.view.rightAnchor),
            trackview.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
        ])

        trackview.start()
        
        
        
        
        
//        self.newWindow = UIWindow()
//        self.newWindow?.backgroundColor = UIColor.clear
//        self.newWindow?.windowLevel = .normal
//        self.newWindow?.isHidden = false
//
//        let vc = TestViewController(nibName: "TestViewController", bundle: nil)
//
//        vc.dismiss = { [weak self] in
//
//            self?.hiddenWindow()
//        }
//        self.newWindow?.rootViewController = vc
//        self.newWindow?.rootViewController?.view.backgroundColor = UIColor.clear
//        self.newWindow?.makeKeyAndVisible()
        
//        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
//
//            let vc = Test2ViewController(nibName: "Test2ViewController", bundle: nil)
//            self.present(vc, animated: true, completion: nil)
//        }
    }
}
